// 引入 express 框架
const express = require('express')
var bodyParser = require('body-parser')
// 创建网站服务器
const app = express();
//访问静态界面
app.use(express.static('www'))
//访问上传文件
app.use('/uploads',express.static('uploads'))


//解析body中间件
app.use(bodyParser.json({ limit: '100mb' }))

app.all("*", function (req, res, next) {
    //设置允许跨域的域名，*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin", "*");
    //允许的header类型
    res.setHeader("Access-Control-Allow-Headers", "Content-Type,Access-Token");
    //对客户端自定义请求头的应答
    res.setHeader("Access-Control-Allow-Headers", "Content-Type,Token");
    //跨域允许的请求方式 
    res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.sendStatus(200)
    else
        next();
})

//wx
const wxRouter = require('./wx')
wxRouter(app)
//admin
const adminRouter = require('./admin')
adminRouter(app)



app.listen(3000);